<template>
  <div class="news-center">
    <client-carousel arrows="never" :url="banner" />
    <div class="news-title">
      <h2>资讯中心</h2>
    </div>
    <div class="news-content">
      <div class="news-box">
        <div class="news-left">
          <div
            v-for="(i, k) in dataList"
            :key="k"
            class="news-item"
            @click="handleDetail(i)"
          >
            <div class="left">
              <img :src="baseURL + i.coverUrl" />
            </div>
            <div class="right">
              <h1>{{ i.newsTittle || "无" }}</h1>
              <div class="time">{{ i.createTime || "--" }}</div>
            </div>
          </div>
          <div class="page-footer">
            <el-pagination
              :total="total"
              v-model:current-page="queryParams.params.pageNum"
              v-model:page-size="queryParams.params.pageSize"
              layout="total, prev, pager, next"
              small
              @size-change="getList"
              @current-change="getList"
            />
          </div>
        </div>
        <div class="news-right">
          <div class="hot-title">最新动态</div>
          <div
            v-for="(i, k) in dataList.slice(0, 5)"
            :key="k"
            class="news-hot"
            @click="handleDetail(i)"
          >
            {{ i.newsTittle || "无" }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { postNewsList } from "@/api/other";
import { useRouter } from "vue-router";
import { getAssetURL } from "@/utils/load_assets";
const router = useRouter();

const baseURL = import.meta.env.VITE_BASE_URL;
const bannerUrl = getAssetURL("client/news/banner.png");
const banner = ref<any>([{ url: bannerUrl }]);

const dataList = ref<any>([]); // 资讯列表
const total = ref(0); // 总条数
const queryParams = ref<any>({
  params: {
    pageNum: 1,
    pageSize: 10,
  },
});

onMounted(() => {
  getList();
});

// 获取资讯列表
const getList = () => {
  postNewsList(queryParams.value).then((res: any) => {
    dataList.value = res.rows;
    total.value = res.total;
  });
};

// 跳转详情
const handleDetail = (row: any) => {
  router.push({
    path: "/client/news/details",
    query: { newsId: row.newsId },
  });
};
</script>
<style scoped lang="less">
.news-center {
  width: 100%;
  min-height: calc(100vh - 400px);
  position: relative;
  .news-title {
    position: absolute;
    left: 0;
    right: 0;
    top: 140px;
    display: flex;
    justify-content: center;
    h2 {
      width: 1200px;
      line-height: 60px;
      font-size: 40px;
      font-weight: 600;
      color: #fff;
      letter-spacing: 1px;
    }
  }
  .news-content {
    display: flex;
    justify-content: center;
    background-color: #fff;
    .news-box {
      width: 1200px;
      display: flex;
      padding-top: 30px;
      .news-left {
        flex: 1;
        .news-item {
          display: flex;
          padding: 36px 0;
          border-bottom: 1px dashed rgba(200, 203, 216, 0.457);
          &:hover {
            cursor: pointer;
            .right h1 {
              color: #4098ff;
            }
          }
          .left {
            width: 246px;
            height: 146px;
            img {
              width: 100%;
              height: 100%;
            }
          }
          .right {
            flex: 1;
            margin-left: 24px;
            margin-top: 12px;
            h1 {
              font-size: 18px;
              font-weight: 500;
              color: #212a40;
              line-height: 32px;
              margin-bottom: 6px;
            }
            .time {
              font-size: 14px;
              font-weight: 400;
              color: #6d7383;
              line-height: 20px;
            }
          }
        }
        .page-footer {
          display: flex;
          justify-content: flex-end;
          margin: 20px 0;
        }
      }
      .news-right {
        width: 280px;
        margin-left: 20px;
        .hot-title {
          font-size: 18px;
          font-weight: 600;
          color: #212a40;
          line-height: 32px;
          padding-bottom: 20px;
          margin: 0;
          border-bottom: 1px dashed rgba(200, 203, 216, 0.457);
        }
        .news-hot {
          padding: 20px;
          font-size: 16px;
          word-spacing: 1px;
          color: #212a40;
          border-bottom: 1px dashed rgba(200, 203, 216, 0.457);
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          &:hover {
            cursor: pointer;
            color: #4098ff;
            background-color: rgba(152, 181, 255, 0.1);
          }
        }
      }
    }
  }
}
</style>
